﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication1.Models.DB;

namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult PhoneData()
        {
            List<Products> list = null;
            using (PhoneDBEntities db = new PhoneDBEntities())
            {
                list = db.Products.ToList();
            }
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        public ActionResult Delete(int delId)
        {
            using (PhoneDBEntities db = new PhoneDBEntities())
            {
                var p = db.Products.Find(delId);
                db.Products.Remove(p);
                if (db.SaveChanges() > 0)
                {
                    return Json(new { code = 0, msg = "删除成功" }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(new { code = 1, msg = "删除失败" }, JsonRequestBehavior.AllowGet);
                }

            }

        }
    }
}